<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>普通运价维护</title>
  </head>
  <body>
    <div id="commondpricegrid" style="height:480px;">
    </div>
    <br>
    <script>
        /*
         * Ext JS Library 2.2
         * Copyright(c) 2006-2008, Ext JS, LLC.
         * licensing@extjs.com
         *
         * http://extjs.com/license
         */
        //为了一般JS方法可以调用，这个变量定义要放在onReady外面．
        var commonPriceReleasedListDS;
        var customerHistoryWin;
        Ext.onReady(function(){
            tabs.getItem(0).setTitle('普通运价维护');
            Ext.form.Field.prototype.msgTarget = 'side';
            // fix the bug in codepress - resize
            //Ext.BoxComponent.prototype.setSize('100%', '125px');
            //search Tab
            /************************************************************
             * Display the result in page
             * the column model has information about grid columns
             * dataIndex maps the column to the specific data field in
             * the data store (created below)
             ************************************************************/
            var commonPriceReleasedListCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    id: 'id',
                    header: "Identify",
                    dataIndex: 'id',
                    width: 5,
                    hidden: true
                },{
                    header: "航空公司",
                    width: 15,
                    dataIndex: 'airways'
                }, {
                    header: "出发地点",
                    width: 30,
                    dataIndex: 'airport_from'
                }, {
                    header: "目的地",
                    width: 70,
                    dataIndex: 'airports_to_desc'
                }, {
                    header: "航班",
                    width: 30,
                    dataIndex: 'flights'
                }, {
                    header: "折扣高",
                    width: 10,
                    dataIndex: 'discount_from'
                }, {
                    header: "折扣低",
                    width: 10,
                    dataIndex: 'discount_to'
                }, {
                    header: "佣金比例",
                    width: 10,
                    dataIndex: 'rake_off'
                }, {
                    header: "起始日",
                    width: 17,
                    dataIndex: 'date_begin',
                    renderer: Ext.util.Format.dateRenderer('Y-m-d')
                }, {
                    header: "结止日",
                    width: 17,
                    dataIndex: 'date_end',
                    renderer: Ext.util.Format.dateRenderer('Y-m-d')
                }, {
                    header: "运价状态",
                    width: 15,
                    dataIndex: 'is_released',
                    renderer: renderReleased
                }, {
                    header: "客票类型",
                    width: 15,
                    dataIndex: 'ticket_payment_type',
                    renderer: renderTicketType
                }, {
                    header: "转换PNR",
                    width: 15,
                    dataIndex: 'conversion_pnr',
                    renderer: renderPNR
                }]);
            function renderReleased(value){
                if(value==1){
                    return "启用"
                }else{
                    return "关闭"
                }
            }
            function renderTicketType(value){
                if(value==1){
                    return "BSP"
                }else{
                    return "B2B"
                }
            }
            function renderPNR(value){
                if(value==1){
                    return "是"
                }else{
                    return "否"
                }
            }
            /************************************************************
             * connect to backend - grid - core part
             * create the Data Store
             *   connect with backend and list the result in page
             *   through JSON format
             ************************************************************/
            commonPriceReleasedListDS = new Ext.data.Store({
                // load using script tags for cross domain, if the data in on the same domain as
                // this page, an HttpProxy would be better
                proxy: new Ext.data.HttpProxy({
                    url: '/ticket/getCommonPriceReleased'
                }),
                // create reader that reads the Topic records
                reader: new Ext.data.JsonReader({
                    root: 'root',
                    totalProperty: 'totalProperty',
                    id: 'id'
                }, [{
                        name: 'id'
                    }, {
                        name: 'airport_from',
                        mapping:'airport_from.airport_name'
                    },{
                        name: 'airways',
                        mapping: 'airways.airways_name'
                    }, {
                        name: 'airports_to_desc'
                    }, {
                        name: 'flights'
                    }, {
                        name: 'discount_from'
                    }, {
                        name: 'discount_to'
                    }, {
                        name: 'rake_off'
                    }, {
                        name: 'date_begin'
                    }, {
                        name: 'date_end'
                    }, {
                        name: 'is_released'
                    }, {
                        name: 'conversion_pnr'
                    }, {
                        name: 'ticket_payment_type'
                    }])
            });
                
                
            /************************************************************
             * add a paging toolbar to the grid's footer
             ************************************************************/
            var myPagingToolbar = new Ext.PagingToolbar({
                pageSize: 10,
                displayInfo: true,
                displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
                emptyMsg: "没有记录",
                store: commonPriceReleasedListDS
            });
                
            /************************************************************
             * Define menubar now in here
             *   add and delete functions
             ************************************************************/
            var menubar = [{
                    text: '删除普通运价',
                    tooltip: 'Remove the selected items',
                    iconCls: 'remove',
                    handler: function(){
                        // delete customer now - action
                        DeleteCommonPrice(commonPriceReleasedListDS, commonPriceReleasedListGridPanel);
                    }
                }, '-', {
                    text: '编辑普通运价',
                    tooltip: '编辑普通运价',
                    iconCls: 'editItem',
                    handler: function(){
                        // delete costlevel now - action
                        EditCommonPrice(commonPriceReleasedListDS, commonPriceReleasedListGridPanel);
                    }
                }];
            /************************************************************
             * define grid panel now
             ************************************************************/
            var commonPriceReleasedListGridPanel = new Ext.grid.GridPanel({
                border: false,
                el: 'commondpricegrid',
                ds: commonPriceReleasedListDS,
                cm: commonPriceReleasedListCM,
                autoWidth: true,
                viewConfig: {
                    forceFit: true
                },
                loadMask: true,
                iconCls: 'icon-grid',
                collapsible: true,
                animCollapse: false,
                autoWidth: true,
                //frame: true,
                title: '普通运价列表',
                tbar: menubar,
                bbar: myPagingToolbar
            });
                
            //panel render
            commonPriceReleasedListGridPanel.render();
            // trigger the data store load
            commonPriceReleasedListDS.load({
                params: {
                    start: 0,
                    limit: 10
                }
            });
        });
        //----------------Delete Customer--------------------------
        function DeleteCommonPrice(dataStore, commonPriceReleasedListGridPanel){
            // get the selected items
            var m = commonPriceReleasedListGridPanel.getSelections();
            if (m.length > 0) {
                Ext.MessageBox.confirm('提示', '你真的要删除这些普通运价吗？', function(btn){
                    if (btn == 'yes') {
                        var jsonData = "[";
                        for (var i = 0, len = m.length; i < len; i++) {
                            var ss = "{\"id\":\"" + m[i].get("id") + "\"}";
                            if (i == 0) 
                                jsonData = jsonData + ss;
                            else jsonData = jsonData + "," + ss;
                            dataStore.remove(m[i]);
                        }
                        jsonData = jsonData + "]";
                        //Ext.MessageBox.alert(jsonData);
                        dataStore.load({
                            params: {
                                start: 0,
                                limit: 10,
                                delData: jsonData
                            }
                        });
                    }
                });
            }
            else {
                Ext.MessageBox.alert('错误提示', '要删除普通运价时，请至少选择一个普通运价');
            }
        };
            
        //------------Edit Customer-----------------
        function EditCommonPrice(commonPriceReleasedListDS, commonPriceReleasedListGridPanel){
            //Ready common combobox
            var m = commonPriceReleasedListGridPanel.getSelections();
            if (m.length > 0) {
                var selectedId = m[0].get("id");
                tabs.getItem(0).getUpdater().update("/ticket/edit_common_price_release?id="+selectedId);//
            }else {
                Ext.MessageBox.alert('提示信息', '编辑时请至少选择一个普通运价');
            }
        }
            
        function search(){
            commonPriceReleasedListDS.baseParams.customer_type = $('customertype').value;
            commonPriceReleasedListDS.baseParams.searchkey = $('searchkey').value;
            commonPriceReleasedListDS.load({
                params: {
                    start: 0,
                    limit: 10
                }
            });
            commonPriceReleasedListDS.baseParams.customer_type = null;
            commonPriceReleasedListDS.baseParams.searchkey = null;
        }
    </script>
  </body>
</html>
